package com.example.springboot0;


import com.example.springboot0.service.OrderServieInf;
import com.example.springboot0.service.imp.OrderServieImp;
import com.example.springboot0.service.imp.UserServicImp;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.example.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import javax.annotation.Resource;
import java.util.stream.Stream;

@SpringBootApplication

public class Springboot0Application implements CommandLineRunner {
	org.aspectj.lang.annotation.Pointcut pointcut;
	public static void main(String[] args) {
		SpringApplication.run(Springboot0Application.class, args);
	}

	// DI
	@Autowired
	ApplicationContext context;

	@Autowired
	AAA a3;

	@Resource(name="AAA")
	AAA a5;

	@Autowired
	@Qualifier("AAA")
	AAA a6;

	@Autowired
	@Qualifier("HHH1")
	HHH a7;


	@Autowired
	OrderServieInf servieImp;

	@Autowired
	UserServicImp userServicImp;

	@Override
	public void run(String... args) throws Exception {

		String[] beannames = context.getBeanDefinitionNames();
		Stream.of(beannames).forEach(item -> {
			System.out.println("name:" + item + "@@@" + context.getBean(item) + "@@@@@" + context.getBean(item).getClass());
		});
		System.out.println("---------------------------------");
		AAA a1 = context.getBean(AAA.class);
		AAA a2 = context.getBean(AAA.class);
		System.out.println(a1);
		System.out.println(a2);
		System.out.println(a3);
		Object a4 = context.getBean("AAA");
		System.out.println(a4);
		System.out.println(a5);
		System.out.println(a6);

		System.out.println(a7);
		System.out.println(a7.getClass());
		System.out.println("----------------------------");
		System.out.println(servieImp);
		System.out.println(servieImp.getClass());
		servieImp.aaa();

		System.out.println(userServicImp);
		System.out.println(userServicImp.getClass());
		userServicImp.bb();

		//
		DDD d = context.getBean(DDD.class);

		d.ddd();
		d.ddd0();

		Student stu = (Student) context.getBean(Student.class);
		System.out.println(stu.getName() + "@" + stu.getAge());

	}
}
